package spring.cloud.service.task.utils;

import lombok.Getter;
import lombok.Setter;

/**
 * <pre>
 *     {
 * 	"code": 0,
 * 	"msg": "操作成功",
 * 	"data": {
 * 		"records": [
 *        {
 * 			"id": 8,
 * 			"createUser": 1,
 * 			"createTime": "2020-03-02 08:44:34",
 * 			"updateUser": 0,
 * 			"updateTime": null,
 * 			"mark": 1,
 * 			"name": "硬件开发工程师",
 * 			"status": 2,
 * 			"sort": 125
 *        }],
 * 		"total": 8,
 * 		"size": 10,
 * 		"current": 1,
 * 		"orders": [],
 * 		"searchCount": true,
 * 		"pages": 1* 	}
 * }
 * </pre>
 */
@Setter
@Getter
public class Result {
    //
    public static final int success_code = 200;
    public static final int fail_code = 500;
    public static final int warn_code = 1024;//[危险]
    public static final String success_msg = "操作成功";
    public static final String fail_msg = "操作失败";
    //
    public static final int table_query_success_code = 0;
    public static final int table_query_fail_code = 1;
    public static final String table_query_success_msg = "操作成功";
    public static final String table_query_fail_msg = "操作失败";
    //
    private int code;
    private String msg;
    private Object data;

    public static Result success() {
        Result response = new Result();
        response.setCode(success_code);
        return response;
    }

    public static Result success(String message) {
        Result response = new Result();
        response.setCode(success_code);
        response.setMsg(message);
        return response;
    }

    public static Result success(String message, Object body) {
        Result response = new Result();
        response.setCode(success_code);
        response.setMsg(message);
        response.setData(body);
        return response;
    }

    public static Result success(Object body) {
        Result response = new Result();
        response.setCode(success_code);
        response.setData(body);
        return response;
    }

    //
    public static Result fail() {
        Result response = new Result();
        response.setCode(fail_code);
        return response;
    }

    public static Result fail(String message) {
        Result response = new Result();
        response.setCode(fail_code);
        response.setMsg(message);
        return response;
    }

    public static Result warn(String message) {
        Result response = new Result();
        response.setCode(warn_code);
        response.setMsg(message);
        return response;
    }

    public static Result fail(String message, Object body) {
        Result response = new Result();
        response.setCode(fail_code);
        response.setMsg(message);
        response.setData(body);
        return response;
    }

    public static Result fail(Object body) {
        Result response = new Result();
        response.setCode(fail_code);
        response.setData(body);
        return response;
    }
}
